﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;
using Wicresoft.EKA.NRemedy.Linq;
using System.Configuration;
using System.Collections;
using BMC.ARSystem;

namespace Wicresoft.EKA.NRemedy.Test
{
    [TestClass]
    public class UnitTest4
    {
        [TestMethod]
        public void TestMethod1()
        {
            string ARServer = ConfigurationManager.AppSettings["ARServer"];
            string ARUid = ConfigurationManager.AppSettings["ARUid"];
            string ARPwd = ConfigurationManager.AppSettings["ARPwd"];

            GlobalSettings.SetCharacterEncoding("UTF8");    //GlobalSetting 里面 
            ARLoginContext context = new ARLoginContext(ARServer, ARUid, ARPwd);
            ARProxy<TestModel> ar = new ARProxy<TestModel>(context);

            //var x = context.ServerInstance.GetEntryStatistics("Test", null, TestModel.IntegerField_Name.S(), 2, 
            //    new int[] { (int)TestModel.Submitter_ID, (int)TestModel.ShortDescription_ID });

            var x = context.ServerInstance.GetEntryStatistics("Test", null, null, 1,
    new int[] { (int)TestModel.Submitter_ID, (int)TestModel.ShortDescription_ID });

            ARSet<TestModel> arset = new ARSet<TestModel>();


            //group by
            //var entry = from a in arset
            //            where a.Submitter.StartsWith("Demo")
            //            orderby a.ShortDescription, a.Status descending
            //            group a by new { a.AssignedTo, a.CharacterField,a.CreateDate } into ddd
            //            select new { ddd.Key, ddddddd = ddd.Average(o => o.DecimalNumberField) };


            //select and page
            var entry = (from a in arset
                         where !a.Submitter.StartsWith("Demo")||(a.ShortDescription.EndsWith("END")&&a.ShortDescription.StartsWith("Start"))
                         orderby a.CreateDate descending, a.Status descending
                         select new { a.CreateDate, a.ShortDescription, a.RequestID }).Skip(0).Take(5);

            //select new { aa = a.ShortDescription, count = a.ShortDescription }).Skip(100).Take(100)


            var aa = entry.GetResult<TestModel>(context);

            

            var x1 = 1;

        }
    }
}
